package com.demo.controller.job;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.exceptions.ExceptionUtil;
import com.demo.handle.RebateNotifyHandle;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * 定时任务
 * @Author wuby
 * @Date 2020/6/23 10:45
 */
@RestController
@RequestMapping("/job")
@Slf4j
public class JobController {

    @Resource
    private RebateNotifyHandle rebateNotifyHandle;



	/**
	 * 返利通知
	 */
	@RequestMapping(value = "/rebateNotify")
	public void rebateNotify(HttpServletRequest req) {
		String dodate = req.getParameter("dodate");
        String startHour = req.getParameter("startHour");
        String endHour = req.getParameter("endHour");
		if (StringUtils.isBlank(dodate)) {
			// 按日
			dodate = DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN);
		}
		if(StringUtils.isBlank(startHour)) {
		    startHour = "00";
        }
		if(StringUtils.isBlank(endHour)) {
		    endHour = "23";
        }
        try {
			log.info("返利通知【开始】，日期：{}",dodate);
            //rebateNotifyHandle.doRebateNotify(dodate,startHour,endHour);
            rebateNotifyHandle.doExec(dodate,startHour,endHour);
			log.info("返利通知【结束】，日期：{}",dodate);
		} catch (Exception e) {
			String message = ExceptionUtil.getMessage(e);
			log.error(message, e);
		}
	}


}
